<?

	include("inc/config.inc.php");

	// Check we are HR!
	if ($_SESSION[role] != "HR")
		die ("Error 71 - User error - Please contact support.");

	$startdate = mysqli_real_escape_string($con,$_POST[startdate]);
	$enddate = mysqli_real_escape_string($con,$_POST[enddate]);
	$name = mysqli_real_escape_string($con,$_POST[name]);
	$requestid = mysqli_real_escape_string($con,$_POST[requestid]);
	$yp=1;
	$days = 0;

	 // Check both dates are in same year period
        if (substr($startdate, 0, 4) == substr($enddate, 0, 4))
                $yp = substr($startdate, 0, 4);
        else
                die("Error 72 - Date range error. Start and end must be in the same year.");

	// Calculate how many days are required for this request (Remove weekends and bank holidays)
        $days = daysCalculation($startdate, $enddate, 'am', 'pm');


	if ($_POST['new'] == "true")
		mysqli_query($conn, "INSERT INTO requests SET user='', description='$name', startdate='$startdate', enddate='$enddate', starttime='am', endtime='pm', yearperiod='$yp', days='$days', status='Accepted', statusmessage='Compulsory Holiday'");
	else
		$result = mysqli_query($conn, "UPDATE requests SET startdate='$startdate', enddate='$enddate', days='$days', yearperiod='$yp', description='$name' WHERE requestid='$requestid'");
		

	header("Location:chol.php");

?>
